home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / ACL / Examples / ACL-World / Sources / ComposedAnim.cp < prev    next >
Encoding:
Text File  |  1994-10-01  |  5.4 KB  |  236 lines  |  [TEXT/MMCC]

  1.  
  2. /********************************************
  3.  **** ACL-World
  4.  ****
  5.  **** Controls.cp
  6.  ****
  7.  **** Created:      25 August 1994
  8.  **** Modified:     30 August 1994
  9.  **** Version:      0
  10.  **** Compatible:   C++, Mac System 7
  11.  ****
  12.  **** Description:    ComposedAnim demo.
  13.  ****
  14.  *******************/
  15.  
  16. #include "ACL-World.h"
  17.  
  18. //*************************************
  19.  
  20.  
  21. static const short PICT_HAT         = 150;
  22. static const short PICT_CAPE         = 149;
  23. static const short PICT_ANTENNA        = 151;
  24.  
  25. static const short PICT_BACKGROUND    = 155;
  26.  
  27. //*************************************
  28.  
  29.  
  30.  
  31. AnimFrameDef anim_antenna[] =         {{PICT_ANTENNA+0,NULL,2,0,0,afcmd_frame},
  32.                                     {PICT_ANTENNA+1,NULL,1,0,0,afcmd_frame},                                    
  33.                                     {PICT_ANTENNA+2,NULL,1,0,0,afcmd_frame},
  34.                                     {PICT_ANTENNA+3,NULL,2,0,0,afcmd_endanim}};        
  35.  
  36.  
  37. //*************************************
  38.  
  39. #define    TEXTSTEP1    "\pSuppose there are three objects: A character, a hat and a cape."
  40. #define    TEXTSTEP2    "\pObjects should be placed like that."
  41.  
  42. #define    TEXTSTEP3    "\pWhat happens if the character moves ? The hat and the cape just won't.  You could move the hat and the cape together with the character, but it is not very convenient to define one move per object."
  43.  
  44. #define    TEXTSTEP4    "\pThe problem is that the hat and the cape are linked to the global animation context. However ACL allows all moveable objects to be linked to an Anim object rather than to be linked to the global animation context."
  45.  
  46.  
  47. #define    TEXTSTEP5    "\pThe hat and the cape should be linked to the character. The character is the supervisor of the two objects. Now when the character moves all its sub-objects move too."
  48.  
  49. #define    TEXTSTEP6    "\pSuppose that there is a new object which should be placed on the top of the hat. "
  50.  
  51. #define    TEXTSTEP7    "\pOne has only to link the antenna to the hat. The hat becomes the supervisor of the antenna."
  52.  
  53. #define    TEXTSTEP8    "\pWhen the hat moves the antenna moves too."
  54.  
  55. #define    TEXTSTEP9    "\pAn Anim object can be structured as a tree without any level limits. The tree above shows you the structure of the character."
  56.  
  57. #define    TEXTSTEP10    "\pNote that not only Anim objects may have sub-objects, all moveable objects (like AnimMask or AnimCollision object) may be supervisors and/or sub-objects." 
  58.                 
  59.                     
  60. //*************************************
  61.  
  62. static AnimGfx        *background;
  63. static short        backwidth,backheight;
  64. static Anim            *anims[4];
  65. static AnimControl    controls[2];
  66.  
  67. //*************************************
  68.  
  69.  
  70. static Boolean    testout(AnimCObject *a, AnimControl *c)    // Test if the anim is out of screen.
  71. {
  72.     if (a->getx()>=backwidth) 
  73.     {
  74.         return TRUE;
  75.     }
  76.     
  77.     return FALSE;
  78. }
  79.  
  80. //*************************************
  81.  
  82. Boolean ACLWorld::companim_advance(void)
  83. {
  84.     short     i;
  85.     Handle     ha;
  86.     Rect    rect;
  87.  
  88.     static short w,h;
  89.  
  90.     step++;
  91.     
  92.     GetDItem(dialog,1,&i,&ha,&rect);
  93.     
  94.     switch(step)
  95.     {
  96.         case 1:
  97.         SetIText(ha,TEXTSTEP1);
  98.         anims[0] = animbase->createanim(animpers);
  99.         anims[1] = animbase->createanim(PICT_HAT);
  100.         anims[2] = animbase->createanim(PICT_CAPE);
  101.         
  102.         anims[0]->findmaxsize(&w,&h);
  103.         anims[0]->place((backwidth/2)-(w/2),(backheight/2)-(h/2));
  104.         anims[1]->place(anims[0]->getx()+20,anims[0]->gety()-16);
  105.         anims[2]->place(anims[0]->getx()+3,anims[0]->gety()+18);
  106.         anims[1]->move(-60,-10);
  107.         anims[2]->move(-60,10);
  108.                 
  109.         return FALSE;
  110.  
  111.         case 2:
  112.         SetIText(ha,TEXTSTEP2);
  113.         anims[1]->move(60,10);
  114.         anims[2]->move(60,-10);                
  115.         return FALSE;
  116.  
  117.         case 3:
  118.         SetIText(ha,TEXTSTEP3);
  119.         controls[0].cmd = acmd_move;
  120.         controls[0].x = 4;
  121.         controls[0].y = 0;
  122.         controls[0].next = &controls[1];
  123.         
  124.         controls[1].cmd = acmd_place;
  125.         controls[1].x = -w;
  126.         controls[1].y = anims[0]->gety();
  127.         controls[1].next =     &controls[0];
  128.         controls[1].testproc = &testout;            
  129.         anims[0]->runcontrol(controls);
  130.  
  131.         return FALSE;
  132.  
  133.         case 4:
  134.         SetIText(ha,TEXTSTEP4);
  135.         return FALSE;
  136.  
  137.         case 5:
  138.         SetIText(ha,TEXTSTEP5);
  139.         anims[1]->setanimsupervisor(anims[0]);
  140.         anims[2]->setanimsupervisor(anims[0]);
  141.         anims[1]->place(20,-16);
  142.         anims[2]->place(3,18);                        
  143.         return FALSE;
  144.  
  145.         case 6:
  146.         SetIText(ha,TEXTSTEP6);
  147.         anims[3] = animbase->createanim(anim_antenna);
  148.         anims[3]->place(60,60);
  149.         return FALSE;
  150.  
  151.         case 7:
  152.         SetIText(ha,TEXTSTEP7);
  153.         anims[3]->findmaxsize(&w,&h);
  154.         anims[3]->setanimsupervisor(anims[1]);
  155.         anims[3]->place(-2,-h);
  156.         return FALSE;
  157.  
  158.         case 8:
  159.         SetIText(ha,TEXTSTEP8);
  160.         anims[1]->move(0,-10);
  161.         return FALSE;
  162.  
  163.         case 9:
  164.         SetIText(ha,TEXTSTEP9);
  165.         animbase->installbackground(PICT_BACKGROUND);
  166.         anims[1]->move(0,10);
  167.         anims[0]->place(30,110);
  168.         anims[0]->stopcontrol();
  169.         return FALSE;
  170.         
  171.         case 10:
  172.         SetIText(ha,TEXTSTEP10);
  173.         return FALSE;
  174.         
  175.     }
  176.     
  177.     
  178.     return TRUE;
  179. }
  180.  
  181.  
  182.  
  183. //*************************************
  184.  
  185. Boolean ACLWorld::do_companim(void)
  186. {
  187.     Point p;
  188.     char  key;
  189.     short res;
  190.     Boolean done = FALSE;
  191.  
  192.     pleasewait(TRUE);
  193.  
  194.     animbase = new AnimBase();
  195.     
  196.     animbase->newgfx(PICT_BACKGROUND);
  197.     animbase->newgfx(PICT_CAPE);
  198.     animbase->newgfx(PICT_HAT);
  199.  
  200.     animbase->preload_framedef(anim_antenna);
  201.     animbase->preload_framedef(animpers);
  202.  
  203.     backwidth = 460;
  204.     backheight = 217;
  205.         
  206.     animbase->buildbuffer(460,217);
  207.     animbase->setbasex(17);
  208.     animbase->setbasey(8);
  209.  
  210.  
  211.     pleasewait(FALSE);
  212.  
  213.     step = 0;
  214.     openbasedialog();
  215.     SetWTitle(dialog,"\pComposed anim");
  216.     companim_advance();
  217.  
  218.     
  219.     for(;;)
  220.     {
  221.         res = processbasedialog(key,p);
  222.         
  223.         if         (res==DO_QUIT) {done=TRUE; break;}
  224.         else if (res==DO_MENU) break;
  225.         else if (res==DO_CONTINUE && companim_advance()) break;
  226.     }
  227.     
  228.     closebasedialog();
  229.     
  230.     delete animbase;
  231.  
  232.     return done;
  233. }
  234.  
  235. //*************************************
  236.